package com.wondedDream.service.impl;

import com.wondedDream.model.UserMockExamRecord;
import com.wondedDream.repository.UserMockExamRecordRepository;
import com.wondedDream.service.UserMockExamRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserMockExamRecordServiceImpl implements UserMockExamRecordService {
    @Autowired
    private UserMockExamRecordRepository userMockExamRecordRepository;

    @Override
    public UserMockExamRecord saveUserMockExamRecord(UserMockExamRecord record) {
        return userMockExamRecordRepository.save(record);
    }

    @Override
    public UserMockExamRecord getUserMockExamRecordById(Integer recordId) {
        return userMockExamRecordRepository.findById(recordId).orElse(null);
    }

    @Override
    public List<UserMockExamRecord> getUserMockExamRecordsByUser(Integer userId) {
        return userMockExamRecordRepository.findByUserId(userId);
    }

    @Override
    public List<UserMockExamRecord> getUserMockExamRecordsByMockExam(Integer mockExamId) {
        return userMockExamRecordRepository.findByMockExamId(mockExamId);
    }

    @Override
    public List<UserMockExamRecord> getAllUserMockExamRecords() {
        return userMockExamRecordRepository.findAll();
    }

    @Override
    public void deleteUserMockExamRecord(Integer recordId) {
        userMockExamRecordRepository.deleteById(recordId);
    }

    @Override
    public UserMockExamRecord updateUserMockExamRecord(UserMockExamRecord record) {
        return userMockExamRecordRepository.save(record);
    }
}